#include <iostream>
#include <vector>
using namespace std;

// 设计循环赛日程表
vector<vector<int>> match(int n) {
    // 创建二维数组 a，大小为 (n+1) x (n+1)
    vector<vector<int>> a(n + 1, vector<int>(n + 1, 0));
    
    // 初始化第一行
    for (int i = 1; i <= n; i++) {
        a[1][i] = i;
    }

    int m = 1;
    while (n > 1) {
        n /= 2;
        for (int t = 1; t <= n; t++) {
            for (int i = m + 1; i <= 2 * m; i++) {
                for (int j = m + 1; j <= 2 * m; j++) {
                    a[i][j + (t - 1) * m * 2] = a[i - m][j + (t - 1) * m * 2 - m];
                    a[i][j + (t - 1) * m * 2 - m] = a[i - m][j + (t - 1) * m * 2];
                }
            }
        }
        m *= 2;
    }
    return a;
}

int main() {
    int n = 8;
    vector<vector<int>> table = match(n);

    // 打印表头
    for (int i = 1; i <= n - 1; i++) {
        cout << "\tR" << i;
    }
    cout << endl;

    // 打印比赛日程表
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (j == 1) {
                cout << "P" << table[i][1];
            } else {
                cout << "\t" << table[i][j];
            }
        }
        cout << endl;
    }

    return 0;
}